package cn.hiapi.admin.api;

import cn.hiapi.admin.query.ActivityLotteryAdQuery;
import cn.hiapi.admin.vo.ActivityLotteryAdVo;
import cn.hiapi.basic.ResponseEntity;
import cn.hiapi.basic.controller.BasicCurdController;
import cn.hiapi.basic.exception.BasicException;
import cn.hiapi.basic.security.TokenGet;
import cn.hiapi.basic.token.Token;
import cn.hiapi.interfaces.DispatchContext;
import cn.hiapi.interfaces.config.IConfigService;
import cn.hiapi.interfaces.finance.IPaymentService;
import cn.hiapi.interfaces.finance.model.PayTypes;
import cn.hiapi.interfaces.finance.model.RechargeModel;
import cn.hiapi.shop.api.platform.vo.ShopVo;
import cn.hiapi.shop.entity.shop.Shop;
import cn.hiapi.shop.service.shop.ShopLinkUserService;
import cn.hiapi.shop.service.shop.ShopService;
import cn.hiapi.shopkeeper.consts.AppConst;
import cn.hiapi.shopkeeper.entity.activity.ActivityLotteryAd;
import cn.hiapi.shopkeeper.enums.ActivityType;
import cn.hiapi.shopkeeper.service.activity.ActivityLotteryAdService;
import cn.hiapi.utils.JsonUtils;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author AdinZ
 * @date 2023/2/4 16:27
 */
@RestController
@RequestMapping("/manage/activity-ad")
public class AdminActivityAdController extends BasicCurdController<ActivityLotteryAd, Long, ActivityLotteryAdVo, ActivityLotteryAdQuery> {

    public AdminActivityAdController(ActivityLotteryAdService basicService, DispatchContext dispatchContext) {
        super(basicService, dispatchContext);
    }

    @Override
    public ActivityLotteryAd parseData(ActivityLotteryAdVo data) {
        return null;
    }

    @Override
    public List<ActivityLotteryAdVo> toListVo(List<ActivityLotteryAd> list, String[] fields) {
        return list.stream().map(e -> this.toData(e, fields)).collect(Collectors.toList());
    }

    @Override
    public ActivityLotteryAdVo toData(ActivityLotteryAd data, String[] fields) {
        ActivityLotteryAdVo vo = data.copy(new ActivityLotteryAdVo());
        Shop shop = this.dispatchContext.getServiceOne(ShopService.class).get(data.getShopId());
        if (shop != null) {
            vo.setShop(JsonUtils.builder()
                    .put("name", shop.getName())
                    .put("logo", shop.getLogo())
                    .build());
        }
        return vo;
    }


}
